if (!window._activedRouters) {
    window._activedRouters = []

    _bus.on(_events.onDeleteRouter, r => {
        window._activedRouters = _activedRouters.filter(e => e.path !== r.path)
        _bus.send(_events.onRouterChange, _activedRouters)
    })
}

const root = '/'

export default function (router, base) {
    router.afterEach((to, from) => {
        if (to.meta && to.meta.container) return

        console.log('aaaa', to)

        const base = router.options.base
        if (base === root && to.path === root) return
        const realPath = base !== root ? (base + to.path) : to.path

        _activedRouters.forEach(e => {
            e.current = false
        })
        const el = _activedRouters.find(e => e.path === realPath)
        console.log('aaaaa', el)
        if (el) {
            el.current = true
            el.params = to.params
            el.query = to.query
        } else {
            let id
            if (to.matched) {
                try {
                    const last = to.matched[to.matched.length - 1]
                    id = last.components.default._Ctor[0].cid
                } catch (e) {
                    console.log(e)
                }
            }
            _activedRouters.push({
                title: to.meta.title,
                current: true,
                path: realPath,
                params: to.params,
                query: to.query,
                id
            })
        }

        _bus.send(_events.onRouterChange, _activedRouters)
    })
}
